<html>
<meta charset="UTF-8">
<head>
    <title>1+1=?</title>
    <!--<script src="https://unpkg.com/vue"></script>-->
    <script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.17.1/axios.min.js"></script>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/fetch/2.0.3/fetch.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div id="app" style="text-align: center">
    <div style="border: dotted">
    <p class="lead">芝士复活</p>
    1.输入手机号<input  type="text" v-model="inputval" style="width: 200px;height: 70px">
    <button type="button" class="btn btn-info" style="width: 100px;height: 70px;" @click="verifyCode">获取验证码</button> <span>{{yzmmsg}}</span>
    <br>
    <br>
   2. 输入验证码<input type="text" v-model="verifycode" style="width: 100px;height: 70px">
    输入邀请码<input style="width: 100px;height: 70px" type="text" v-model="invitecode">
    <button style="width: 100px;height: 70px;" @click="go" type="button" class="btn btn-success">开始刷复活卡</button>
    <div v-for="item in msg">{{item}}</div>
    </div>
    <div>{{msg}}</div>
    <div style="border: dotted">
        <p class="lead">西瓜复活</p>
        1.输入手机号<input  type="text" v-model="inputval2" style="width: 200px;height: 70px">
        <button type="button" class="btn btn-info" style="width: 100px;height: 70px;" @click="verifyCode2">获取验证码</button> <span>{{yzmmsg2}}</span>
        <br>
        <br>
        <!--2. 输入验证码<input type="text" v-model="verifycode2" style="width: 100px;height: 70px">-->
        <!--输入邀请码<input style="width: 100px;height: 70px" type="text" v-model="invitecode2">-->
        <!--<button style="width: 100px;height: 70px;" @click="go2" type="button" class="btn btn-success">开始刷复活卡</button>-->
        <!--<div v-for="item in msg2">{{item}}</div>-->
    </div>
    </div>
</div>
<script>
    
    var app = new Vue({
        el: '#app',
        data: {
            inputval: '',
            request_id:"",
            verifycode:'',
            invitecode:'',
            msg:[],
            yzmmsg:'',
            inputval2: '',
            request_id2:"",
            verifycode2:'',
            invitecode2:'',
            msg2:[],
            yzmmsg2:'',


        },
        watch: {

        },
        methods: {
            verifyCode(){
                var that= this
                that.yzmmsg = ""
                axios.post('/cdapi/zsyzm',{
                    phone:this.inputval
                }).then(function (res) {
                    if(res.data.error_msg == "操作成功"){
                        that.yzmmsg = res.data.error_msg
                        that.request_id = res.data.request_id
                        console.log("request_id:",that.request_id)
                    }else{
                        that.yzmmsg = "error"
                    }
                }).catch(function (err) {
                    console.log("error is",res);
                })
            },
            go(){
                var that = this
                axios.post('/cdapi/login',{
                    phone:this.inputval,
                    code:this.verifycode,
                    inviteCode:this.invitecode,
                    request_id:this.request_id
                }).then(function (res) {

                    axios.post('/cdapi/fuhuo',{
                        uid:res.data.uid,
                        session:res.data.session,
                        inviteCode:that.invitecode
                    }).then(function (res) {
                        console.log("res=",res)
                        var info = res.data.text!=null?',但此号码'+res.data.text:''
                        that.msg.push(res.data.error_msg+info);
                        that.verifycode='';
                        that.inputval='';
                    }).catch(function (err) {
                        that.verifycode='';
                        that.inputval='';
                        that.msg.push("出错,请联系管理员"+err)

                    })

                }).catch(function (err) {
                    that.msg.push("出错,请联系管理员"+err)                })
            },
            verifyCode2(){
                this.yzmmsg2 = ''
                var that= this
                axios.post('/cdapi/xgyzm',{
                    phone:this.inputval2
                }).then(function (res) {
                    that.yzmmsg2 = res.data.message
                    this.inputval2=''
                    console.log("西瓜验证码请求返回:",res.data)
                }).catch(function (err) {
                    that.yzmmsg2 = "error"
                    this.inputval2=''
                    console.log("error is",res);
                })
            },
            go2(){
                var that = this
                axios.defaults.withCredentials = true
                axios.post('/cdapi/xgyzmlogin',{
                    phone:this.inputval2,
                    code:this.verifycode2
                }).then(res=>{
                    console.log("登入",res)
                    var session_key = res.data.data.session_key
                    var uid = res.data.data.user_id
                    axios.post('/cdapi/xgfuhuo',{
                        sessionkey : session_key,
                        uid:uid,
                        invitecode:that.invitecode2

                    }).then(res=>{

                    })
                }).catch(function (err) {
                    that.msg2.push("出错,请联系管理员"+err)
                })
            }
        }

    })
</script>
</body>
</html>